Binary Semaphore

To get rid of the problem of wasting the wake-up signals, Dijkstra proposed an approach which involves storing all the wake-up calls. Dijkstra states that, instead of giving the wake-up calls directly to the consumer, producer can store the wake-up call in a variable. Any of the consumers can read it whenever it needs to do so. Semaphore is the variables which storesthe entire wake up calls that are being transferred from producer to consumer. It is a variable on which read, modify and update happens automatically in kernel mode. Semaphore cannot be implemented in the user mode because race condition may always arise when two or more processes try to access the variable simultaneously. It always needs support from the operating system to be implemented.

In counting semaphore, Mutual exclusion was not provided because we has the set of processes which required to execute in the critical section simultaneously. However, Binary Semaphore strictly provides mutual exclusion. Here, instead of having more than 1 slots available in the critical section, we can only have at most 1 process in the critical section. The semaphore can have only two values, 0 or 1. Let's see the programming implementation of Binary Semaphore.

Buttons overview

Home : In navbar home button is to jump to main page
Dropdown : To jump to any algorithm
Info panel : Displays the value of each required queue and semaphore.
Add Process: On clicking this button new process will be added.
P0 : On clicking this button P0 process will move forward according to algorithm.
save PDF : To save all the status of each stage of algorithm .

Tool Tips

Tooltips will help to get information about the hovered element.
here element with tooltips are:
semaphore, suspended queue, critical section, completed queue, Added, Entry, CS, Exit

To CS

By clicking the button the process will be moved to Critical Section if the Critical section is not occupied or semaphore is greater than zero(0).

Add Processes

By clicking Add Processes new processes will be added with the button and process icon.

To Entry Section

Processes will move to suspended queue if the critical section is occupied.
Example: p2 will be moved to suspended queue as critical section is occupied by p0.

Warning

If the process is there in critical section still if any process tries to interrupt then it will show the warning.

Full completion

It's gratitude message to display that all the processes are completed.

Save PDF

By clicking the save PDF the pdf will be formed by collecting all the text in textArea.

Analysis of Binary semaphore approach

1. A binary semaphore has two components-
  a.  An integer value which can be either 0 or 1.
  b.  An associated waiting list (usually a queue).
2. The waiting list of binary semaphore contains the processes that got blocked when trying to enter the critical section.
3. In waiting list, the blocked processes are put to sleep.
4. The waiting list is usually implemented using a queue data structure.
5. Using a queue as waiting list ensures bounded waiting.
6. This is because the process which arrives first in the waiting queue gets the chance to enter the critical section first.
7. The wait operation is executed when a process tries to enter the critical section.
8. The signal operation is executed when a process takes exit from the critical section.
9. Binary semaphores are mainly used for two purposes-
  a. To ensure mutual exclusion.
  b. To implement order in which the process must execute.

abc